/*
 * Copyright (c) 2021. Moses All Right Reserved
 */

package com.moses.design_patterns.iterator;

import java.util.List;

/**
 * @author Moses
 * @email shenhuohui@gmail.com
 * @date 2021/4/16 22:22
 */
public class ProjectIterator implements IIterator {

    private List<Project> projects;
    private int cursor = 0;
    public ProjectIterator(List<Project> projects){
        this.projects = projects;
    }

    // 是否有下一个事物
    @Override
    public boolean hasNext() {
        return cursor < projects.size();
    }

    // 读取下一个事物
    @Override
    public Project next() {
        // 获取后，游标要加一
        if(hasNext()) return projects.get(this.cursor++);
        else return null;
    }
}
